import api from '../../http/apis'
export default {
	namespaced: true,
	state: {
		//onclass
		oneClass:[],
		//附近店铺
		near:[],
		//初始列表数据
		listShop: [],
		//店铺详情
		store:[],
		order:null
	},
	mutations: {
		setOneClass(state,data) {
			state.oneClass = data
		},
		setNear(state,data) {
			state.near = data
		},
		setListShop(state, data) {
			state.listShop = data
		},
		setStore(state,data) {
			state.store = data
		},
		setOrder(state,data) {
			console.log(data);
			state.order = data
		}
	},
	actions: {
		//getOneClassAll
		async getOneClass({commit}, params) {
			const data = await api.getOneClassAll()
			if (data.code == 200) {
				commit("setOneClass",data.data)
			}
		},
		//获取所有4s店铺
		async getShop({commit}, params) {
			const data = await api.getListShop(params)
			if (data.code == 200) {
				commit("setListShop",data.data)
			}
		},
		
		//nearbyStores
		async nearStore({commit}, params) {
			const data = await api.nearbyStores(params)
			if (data.code == 200) {
				commit("setNear",data.data)
			}
		},
		
		//获取4s店铺详情
		async getStoreDetail({commit}, params) {
			const data = await api.getStoreById(params)
			if (data.code == 200) {
				commit("setStore",data.data)
			}
		},
		
		//汽车服务下单
		async carserviceOrder({commit}, params) {
			return await api.createCarservice(params)
		},
		
		//订单详情
		async orderDetail({commit}, params) {
			const data = await api.getOrderDetail(params)
			if(data.code) {
				const thisOrder = data.data.carserviceOrders
				commit("setOrder",thisOrder[thisOrder.length - 1])
			}
		}

	},
}
